import store from '@/store/index.js'
import router from '@/router/index.js'
import gData from '@/util/globalData.js'

router.beforeEach(async (to, from, next) => {
	let token = gData.getLocal('token')
	if (to.name == 'login') {
		next()
		return true
	}
	if (!token) {
		next({ path: '/login' })
	} else {
		if (store.state.app.refresh) {
			let userinfo = gData.getLocal('userinfo')
			store.commit('app/changeTheme', gData.getLocal('theme')) //默认主题
			store.commit('app/changeRefresh', false) //是否刷新
			store.commit('user/changeUserInfo', userinfo) //用户信息
			store.commit('user/changeToken', token) //用户token
			store.commit('app/changeWebHeight', document.documentElement.clientHeight - 84) //计算可用高度
			await store.dispatch('user/getAuthList')
			next()
		} else {
			next()
		}
	}
	// next({
	//     path: '/login',
	//     query: {redirect: to.fullPath}//将跳转的路由path作为参数，登录成功后跳转到该路由
	// })
})
router.afterEach((to, from) => {})
